package my.io.hadoop;


import lombok.RequiredArgsConstructor;

import my.io.hadoop.jobs.db.DBJob;
import my.io.hadoop.jobs.hdfs.HdfsJobByMonth;
import org.apache.hadoop.fs.FileSystem;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@RequiredArgsConstructor
public class Main  implements CommandLineRunner {
    public static void main(String[] args) {
        String userDir = System.getProperty("user.dir");
        System.setProperty("hadoop.home.dir", userDir + "\\winutils-master\\hadoop-3.3.5");
        // 解决org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z问题
        System.load(userDir + "\\winutils-master\\hadoop-3.3.5\\bin\\hadoop.dll");
        SpringApplication.run(Main.class, args);
    }

    private final FileSystem fileSystem;

    private final DBJob dbJob;

    private final HdfsJobByMonth hdfsJobByMonth;

    @Override
    public void run(String... args) throws Exception {
//        System.out.println("========= 获取FS文件目录信息 ============");
//        try {
//            RemoteIterator<LocatedFileStatus> iterator = fileSystem.listFiles(new Path("/"), true);
////            FileStatus[] fileStatuses = fileSystem.globStatus(new Path("/"));
////            for (FileStatus fileStatus : fileStatuses) {
////                System.err.println(fileStatus.getPath());
////                if (fileStatus.isDirectory()) {
////                    FileStatus[] fileStatuses1 = fileSystem.listStatus(fileStatus.getPath());
////                    for (FileStatus status : fileStatuses1) {
////                        System.err.println(status);
////                    }
////                }
////            }
//
//
//            while (iterator.hasNext()) {
//                LocatedFileStatus fileStatus = iterator.next();
//                System.out.println(">" + fileStatus.getPath());
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println("=========== 获取完毕 ===========");
        System.out.println("=========== 运行任务开始 ===========");
//        dbJob.runJob();
//        hdfsJob.runJob();
        System.out.println("=========== 运行任务完成 ===========");
    }
}